package com.fxd.core.valid.util;

import com.fxd.core.util.RR;
import org.springframework.validation.BindingResult;

import java.util.HashMap;
import java.util.Map;

public class BindingResultUtils {

    public static RR bindResult(BindingResult bindingResult) {
        //获取校验的错误结果
        Map<String, String> map = new HashMap<>();
        bindingResult.getFieldErrors().forEach(fieldError -> {
            String message = fieldError.getDefaultMessage();
            String field = fieldError.getField();
            map.put(field, message);
        });
        return RR.error(400, "提交的数据不合法").put("data", map);
    }
}
